package com.yidu.t299.dao.xp;
import com.yidu.t299.domain.xp.*;
import com.yidu.t299.domain.xp.Class;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

/*
使用Mybatis逆向生成自动生成 后续自己更改
 */
@Mapper
public interface StucatabolizeManageMapper {
    /**
     * 根据退班编号删除
     * @param stucataId
     * @return
     */
    @Delete({
        "delete from stucatabolize_manage",
        "where stucata_id = #{stucataId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer stucataId);

    /**
     * 增加退班信息
     * @param record 退班对象
     * @return 影响的行数(返回1则成功)
     */
    @Insert({
        "insert into stucatabolize_manage (stucata_id,student_name,record_id, ",
        "school_id, class_id, ",
        "stucata_dates)",
        "values (#{stucataId,jdbcType=INTEGER},#{studentName,jdbcType=VARCHAR},#{recordId,jdbcType=INTEGER}, ",
        "#{schoolId,jdbcType=INTEGER}, #{classId,jdbcType=INTEGER}, ",
        "#{stucataDates,jdbcType=VARCHAR})"
    })
    int insert(StucatabolizeManage record);

    /**
     * 根据退班编号查询指定的信息
     * @param stucataId 退班编号
     * @return
     */
    @Select({
        "select",
        "stucata_id,student_name,record_id, school_id, class_id, stucata_dates",
        "from stucatabolize_manage",
        "where stucata_id = #{stucataId,jdbcType=INTEGER}"
    })
    @Results(id = "StucatabolizeManageMap",value = {
        @Result(column="stucata_id", property="stucataId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="student_name", property="studentName", jdbcType=JdbcType.VARCHAR),
        @Result(column="record_id", property="recordId", jdbcType=JdbcType.INTEGER),
        @Result(column="school_id", property="schoolId", jdbcType=JdbcType.INTEGER),
        @Result(column="class_id", property="classId", jdbcType=JdbcType.INTEGER),
        @Result(column="stucata_dates", property="stucataDates", jdbcType=JdbcType.VARCHAR)
    })
    StucatabolizeManage selectByPrimaryKey(Integer stucataId);

    /**
     * 按条件分页查询学员数据集合
     * @param rows 每页的行数
     * @param page 页码
     * @param condition 条件参数
     * @return 退班对象集合
     */
    @Select("select * from stucatabolize_manage cm " +
            "join school c " +
            "on cm.school_id=c.school_id " +
            "join class sm " +
            "on sm.class_id=cm.class_id " +
            "join record re " +
            "on cm.record_id=re.record_id where 1=1 ${condition} limit #{page},#{rows}")
    @Results({
            @Result(column = "stucata_id",property = "stucataId",jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "student_name",property = "studentName",jdbcType = JdbcType.VARCHAR),
            @Result(column = "record_id",property = "recordId",jdbcType = JdbcType.INTEGER),
            @Result(column = "school_id",property = "schoolId",jdbcType = JdbcType.INTEGER),
            @Result(column = "class_id",property = "classId",jdbcType = JdbcType.INTEGER),
            @Result(column = "stucata_dates",property = "stucataDates",jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_name",property = "className",jdbcType = JdbcType.VARCHAR),
            @Result(column = "school_name",property = "schoolName",jdbcType = JdbcType.VARCHAR),
            @Result(column = "record_name",property = "recordName",jdbcType = JdbcType.VARCHAR)
    })
    List<StucatabolizeManage> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询stucatabolize_manage表中数据行数
     * 因为涉及了多表所以这里也需要多表联查不然无法设置条件
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("select count(*) from stucatabolize_manage cm " +
            "join school c " +
            "on cm.school_id=c.school_id " +
            "join class sm " +
            "on sm.class_id=cm.class_id " +
            "join record re " +
            "on cm.record_id=re.record_id where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);

    /**
     * 根据退班信息修改其数据
     * @param record
     * @return
     */
    @Update({
            "update stucatabolize_manage",
            "set student_name = #{studentName,jdbcType=VARCHAR},",
            "record_id = #{recordId,jdbcType=INTEGER},",
            "school_id = #{schoolId,jdbcType=INTEGER},",
            "class_id = #{classId,jdbcType=INTEGER},",
            "stucata_dates = #{stucataDates,jdbcType=VARCHAR}",
            "where stucata_id = #{stucataId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(StucatabolizeManage record);

    //以下是获取下拉框数据的方法

    /**
     * 得到所有校区名称信息
     * @return 校区名称集合
     */
    @Select("select school_name from school")
    @Results({
            @Result(id = true,column = "school_name",property = "schoolName")
    })
    List<School> selectAllGetSchoolName();

    /**
     * 得到所有班级名称信息
     * @return 校区名称集合
     */
    @Select("select class_name from class")
    @Results({
            @Result(id = true,column = "class_name",property = "className")
    })
    List<Class> selectAllGetClassName();

    /**
     * 得到所有教师名称信息
     * @return 教师名称集合
     */
    @Select("select record_name from record")
    @Results({
            @Result(id = true,column = "record_name",property = "recordName")
    })
    List<Record> selectAllGetRecordName();

    /**
     *针对校区表(school)进行操作
     * 根据校区名称查找其编号
     * @param schoolName 校区名称
     * @return 影响的行数(>1:成功)
     */
    @Select("select school_id from school where school_name=#{schoolName}")
    int selectBySchoolName(@Param("schoolName") String schoolName);

    /**
     *针对班级表(class)进行操作
     * 根据班级名称查找其编号
     * @param className 班级名称
     * @return 影响的行数(>1:成功)
     */
    @Select("select class_id from class where class_name=#{className}")
    int selectByClassName(@Param("className") String className);

    /**
     *针对教师表(record)进行操作
     * 根据教师名称查找其编号
     * @param recordName 校区名称
     * @return 影响的行数(>1:成功)
     */
    @Select("select record_id from record where record_name=#{recordName}")
    int selectByRecordName(@Param("recordName") String recordName);

}